package cn.walls1717.juc.future;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;

/**
 * 比价需求的前置知识点
 *
 * @author walls1717
 * @create 2022/12/09 14:06
 **/
@Slf4j
public class CompletableFutureMallPreDemo {

    public static void main(String[] args) {
        Student student = new Student();
        // 引入lombok依赖，在类上添加@Accessors(chain = true)即可开启链式编程。
        student.setId(1).setName("Test").setMajor("英语");

        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            return "hello";
        });

        // join与get方法最大的区别就是join在编译器不会报异常，get必须要在编译期处理异常。
        log.info(future.join());
    }
}

@Data
@Accessors(chain = true) // 开启链式编程
@AllArgsConstructor
@NoArgsConstructor
class Student {
    private Integer id;
    private String name;
    private String major;
}
